$(function(){
    init_staff_tracnce();
});
/**初始化部门列表*/
function init_staff_tracnce(){
    $.post(ctx+"dept/getUseeAndDepttree",{},function (r) {
        var array  = r.msg;
        $("#using_json").jstree({
            "core": {
                "multiple": false,//单选
                "data":array
            },
            "checkbox" : {
                "keep_selected_style" : false
            },
            "plugins" : [ "wholerow", "checkbox" ]
        });
        // 获得点击节点的id
        $('#using_json').on("changed.jstree", function (e, data) {
            var nodeid = data.node.id;
            var text = data.node.text;
            var action = data.action;;
            if (action == "deselect_node") {
                $("#user-selectfor").find("div").each(function () {
                    var data_id = $(this).attr("data-id");
                    if (data_id == nodeid) $(this).remove();
                });
            }else{
                var label = "<div class='label label-danger p-3 m-3 pull-left' data-id='"+nodeid+"'>"+text+"</div>";
                $("#user-selectfor").empty().append(label);
            }

        });
    });
}

/**点击转让客户的跟踪人员**/
function bigDisAginMyTransfer() {
    /**记录转让的数据id**/
    var ids = $("#myEmpTable").bootstrapTable("getSelections");
    var ids_arr = "";
    var idss = ""; /**转让得id**/
    var types = ""; /**类型**/
    var names = "";
    if (!ids.length) {$JuXue.n_warning("请勾选需要转让的客户信息！");return;}
    for (var i = 0; i < ids.length; i++) {
        ids_arr += ids[i].uuid;
        idss += ids[i].id;
        types += ids[i].types;
        names += ids[i].nickname;
        if (i !== (ids.length - 1)) {ids_arr += ",";idss += ",";types += ",";names += ",";}
    }
    /**记录转让的人员**/
    var useridsArray = new Array();
    $("#user-selectfor").find("div").each(function () {
        var notselect = $(this).attr("data-id");
        useridsArray.push(notselect);
    });
    if (!useridsArray.length) {$JuXue.n_warning("请选择需要转让的用户信息！");return;}
    var bpDistribute = useridsArray.join(",");
    $("#myCustomer-modal").modal("hide");
    $.post(ctx+"myCustomer/companyMyCustomerTransfer",{"uuid":ids_arr,ids:idss,"types":types,receiver:bpDistribute,"names":names},function (r) {
        if (r.code == 0){
            $JuXue.n_success("转让成功");
            var a = ".theme-panel", b = "active";
            $(a).removeClass(b);
            $("#selectTheme").hide();
            $JuXue.refreshTable('myEmpTable')
        }else{
            $JuXue.n_warning("转让失败");
        }
    });
}
